#include <dbg.h>
#include <gtest/gtest.h>
using namespace std;

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> mp;
        for (string& str : strs) {
            string key = str;
            sort(key.begin(), key.end());
            mp[key].emplace_back(std::move(str));
        }

        dbg(mp);

        vector<vector<string>> res;
        for (auto it = mp.begin(); it != mp.end(); ++it) {
            res.emplace_back(it->second);
        }

        return res;
    }
};

TEST(TEST1, groupAnagrams) {
    Solution s;

    vector<string> strs{"eat", "tea", "tan", "ate", "nat", "bat"};

    vector<vector<string>> res{{"bat"}, {"tan", "nat"}, {"eat", "tea", "ate"}};
    EXPECT_EQ(s.groupAnagrams(strs), res);
}

TEST(TEST2, groupAnagrams) {
    Solution s;

    vector<string> strs{""};

    vector<vector<string>> res{{""}};
    EXPECT_EQ(s.groupAnagrams(strs), res);
}

TEST(TEST3, groupAnagrams) {
    Solution s;

    vector<string> strs{"a"};

    vector<vector<string>> res{{"a"}};
    EXPECT_EQ(s.groupAnagrams(strs), res);
}

int main(int argc, char* argv[]) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}